﻿<?php

if($mode == 'broken') {
	$sql_where = "WHERE m_is_broken = 1";
	$sql_order = "ORDER BY m_id DESC";
}
if($search) {
	$sql_where = "WHERE upload_title LIKE '%".$search."%'";
	$sql_order = "ORDER BY upload_id DESC";
}
else {
	$sql_order = "ORDER BY upload_id DESC";
}
$num = $mysql->query("SELECT * FROM ".$tb_prefix."upload $sql_where");
$total = $mysql->num_rows($num);
if($total) {
	$m_per_page = 30;
	if (!$pg) $pg = 1;
	$sql = "SELECT * FROM ".$tb_prefix."upload $sql_where $sql_order LIMIT ".(($pg-1)*$m_per_page).",".$m_per_page;
	$query = $mysql->query($sql);
		while($row = $mysql->fetch_array($query)) {
			$ads_ID		=	$row['upload_id'];
			$ads_title	=	$row['upload_title'];
			$ads_URL	=	$row['upload_url'];
			$ads_lyric	=	$row['upload_lyric'];
			$ads_cat	=	$row['upload_cat'];
			$ads_ID_poster = $row['upload_poster'];
			$ads_ID_kiemtra = $row['upload_xacnhan'];
			$ads_kiemtra = m_get_data('USER',$ads_ID_kiemtra);			
			$ads_poster	=	m_get_data('USER',$ads_ID_poster);
			$ads_check	=	$row['upload_check'];
			if ( $ads_check == 0)
			{
				$kiemtra = '<font color=red>chưa xác nhận</font>';
				$link1 = '?act=member_post_song&mode=edit&id='.$ads_ID;
			}
			else {
				$kiemtra = '<font color=blue>đã đăng</font>';
				$link1 = '#';
			}
			
			$list_HTML 	   .= "<tr><td><input class=checkbox type=checkbox id=checkbox onclick=docheckone() name=checkbox[] value=$ads_ID></td><td class=fr><a href='".$link1."'><b>".$ads_title."</b></a></td><td class=fr_2 align=center><b><a href=#>$ads_poster</a></b></td><td class=fr_2 align=center><b><a href=#>$ads_kiemtra</a></b></td><td align=center>$kiemtra</td></tr>";
			$view_pages 	= admin_viewpages($total,$m_per_page,$pg);
		}
}
if(!$total) {
	$list_HTML = "<tr><td></td><td align=center>Chưa có bài hát</td></tr>";
}
elseif ($_POST['do']) {
	$arr = $_POST['checkbox'];
	if (!count($arr)) die('Lỗi');
	if ($_POST['selected_option'] == 'del') {
		$in_sql = implode(',',$arr);
		$mysql->query("DELETE FROM ".$tb_prefix."upload WHERE upload_id IN (".$in_sql.")");
		echo "<script language='JavaScript'>{ window.parent.location='?act=member_post' }</script>";
	}		

	exit();
}
include("templates/list_member_post.html");
?>